#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2025 粤港澳大湾区（广东）国创中心

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

File: pyncti_mesh_add_spc.py
Desc: Function to add single point constraints to selected mesh nodes.
Author: xumanjia
Date: 2025-08-01
"""
# 在有网格的状态下选中节点，对该节点添加固定约束
def pyncti_mesh_add_spc(NCTI,doc):
    doc.ResetCaseResult()
    sel = NCTI.SelectionManager(doc)
    res  = doc.ReturnDialogData(-1, "单点约束", 
                                     "约束名称","constraint", 
                                     "平移XYZ","1,2,3",
                                     "平移自由度", "0,0,0",
                                     "旋转XYZ","4,5,6",
                                     "旋转自由度","0,0,0",
                                     "说明","平移方向X、Y、Z分别代表1，2，3",
                                     "","旋转方向X、Y、Z分别代表4，5，6",
                                     "","每个X、Y、Z对应自由度值，0表示固定")
    if len(res) > 0:
        constName = res[0]
        pan = res[1]
        freedomPan = res[2]
        rot = res[3]
        freedomRot = res[4]
        xyz = pan+rot
        free = freedomPan+freedomRot
        intXYZ = list(map(int, xyz.split(',')))
        intFreedom = list(map(int,free.split(',')))
        doc.RunCommand("cmd_ncti_mesh_add_spc", constName, sel.ObjectNames[0], sel.CellIDs, intXYZ, intFreedom)